#include "gauss_blur.h"
#include <stdio.h>
#include <assert.h>

int main() {
    unsigned char input[HEIGHT][WIDTH];
    unsigned char output[HEIGHT][WIDTH];

    int has_errors = 0;
    int expected;

    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            if (i == HEIGHT / 2 || j == WIDTH / 2)
                input[i][j] = 255;
            else
                input[i][j] = 0;
        }
    }

    gaussian_blur(input, output);

    FILE * fp = fopen("check.data", "r");
    assert(fp != NULL && "Couldn't open check data file");

    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            int res = fscanf(fp, "%d", &expected);
            assert(res == 1 && "read check data file failed");
            if (expected != output[i][j]) {
                printf("blur[%d][%d] = %d, expected[%d][%d] = %d\n",
                       i, j,
                       output[i][j],
                       i, j,
                       expected);
                has_errors++;
            }
        }
    }

    fclose(fp);

    if (has_errors) {
        fprintf(stderr, "Benchmark results are incorrect\n");
        return -1;
    }

    printf("Success.\n");
    return 0;
}
